# coding:utf-8
# 曾山
# 时间 2022/5/4 16:31
from flask import g,request,current_app
from comment.utils.token_pyjwt import verify_tokens
'''
定义请求钩子，在请求进来之前得到request携带的token，并且验证token

'''
def jwt_request_authorization():
    g.user_id = None
    try:
        token = request.headers.get('token')
    except Exception as ex:
        current_app.logger.info('请求头中没有token')
        return
    result = verify_tokens(token)
    if 'id' in result:#如果验证成功 字典中一定有用户id
        g.user_id=result['id']


